<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增站点')"/>
    <th:block th:include="include :: summernote-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-site-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="name" id="name" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="title" id="title">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <textarea type="text" name="description" class="form-control" th:rows="5"
                          placeholder="请输描述内容"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">关键字：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="keywords" id="keywords">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">站点域名：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="siteDomain" id="siteDomain">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">背景音乐：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="bgMusic" id="bgMusic">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">版权信息：</label>
            <div class="col-sm-9">
                <input id="copyright" name="copyright" type="hidden">
                <div class="summernote"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="sort" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否显示：</label>
            <div class="col-sm-9">
                <div class="radio-box" th:each="dict : ${@dict.getType('cms_show_hide')}">
                    <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea type="text" name="remark" class="form-control" th:rows="5" placeholder="请输入备注"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: summernote-js"/>
<script type="text/javascript" th:inline="javascript">
    var prefix = ctx + "cms/site";
    $(function () {

    })

    $('.summernote').summernote({
        placeholder: '请输入版权信息',
        height: 320,
        lang: 'zh-CN',
        followingToolbar: false,
        dialogsInBody: true,
        callbacks: {
            onImageUpload: function (files) {
                sendFile(files[0], this);
            }
        }
    });

    // 上传文件
    function sendFile(file, obj) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/upload",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $(obj).summernote('editor.insertImage', result.url, result.fileName);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function (error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            var sHTML = $('.summernote').summernote('code');
            $("#copyright").val(sHTML);
            $.operate.save(prefix + "/addSite", $('#form-site-add').serializeArray());
        }
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $.modal.close(index);
    }
</script>
</body>
</html>
